<template>
  <view>
    <view class="info">
      <view>
        {{ v.title }}
      </view>
      <view>
        {{ v.type }}
      </view>
      <view>
        {{ v.education.name }}
      </view>
      <view>
        {{ v.title }}
      </view>
    </view>
    <button :type="isCollect(v.id) ? 'primary': 'default'"
      @click="handleCollect">{{ isCollect(v.id) ? "已收藏" : "收藏" }}</button>
    <navigator url="../chated/chated" @click="addChat(v)"><button>立即沟通</button></navigator>
  </view>
</template>

<script>
  import {
    mapGetters,
    mapMutations
  } from 'vuex'
  export default {
    onLoad({
      id
    }) {
      this.id = id;
      uni.request({
        url: 'http://localhost:3000/list/' + this.id
      }).then(resp => {
        console.log(resp.data)
        this.v = resp.data
      })
    },
    data() {
      return {
        v: {}
      };
    },
    computed: {
      ...mapGetters('collect', ['isCollect'])
    },
    methods: {
      ...mapMutations('collect', ['addCollect', 'cancelCollect']),
      ...mapMutations('chat', ['addChat']),
      handleCollect() {
        if (this.isCollect(this.v.id)) {
          this.cancelCollect(this.v)
          uni.showToast({
            title: '取消收藏',
            icon: "none"
          })
        } else {
          this.addCollect(this.v)
          uni.showToast({
            title: '加入收藏',
            icon: "none"
          })
        }
      }
    }
  }
</script>

<style lang="scss">

</style>
